﻿using JzSport.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace JzSport.Api
{
    class GetActivityAction : GetAction<Params.GetActivityParams,
        Results.GetActivityResult>
    {
        protected override ActionResult<Results.GetActivityResult> OnExecute(ActionContext context, SysParameters sysParameters,
            Params.GetActivityParams opParams)
        {
            ServiceResult<ActivityDetail> serviceResult = new ActivityService().GetActivity(opParams.ActivityId);

            Results.GetActivityResult actionResult = new Results.GetActivityResult();
            if (serviceResult.ErrorCode == ErrorCode.NoError)
            {
                actionResult.Id = serviceResult.Data.Id;
                actionResult.Title = serviceResult.Data.Title;
                actionResult.CategoryCode = serviceResult.Data.CategoryCode;
                actionResult.CategoryCaption = serviceResult.Data.CategoryCaption;
                actionResult.Address = serviceResult.Data.Address;
                actionResult.BeginTime = serviceResult.Data.BeginTime;
                actionResult.EndTime = serviceResult.Data.EndTime;
                actionResult.City = serviceResult.Data.City;
                actionResult.CostPrePerson = serviceResult.Data.CostPrePerson;
                actionResult.CreatedTime = serviceResult.Data.CreatedTime;
                actionResult.CreatorId = serviceResult.Data.CreatorId;
                actionResult.CreatorName = serviceResult.Data.CreatorName;
                actionResult.CreatorPhone = serviceResult.Data.CreatorPhone;
                actionResult.CreatorNickName = serviceResult.Data.CreatorNickName;
                actionResult.CreatorAvatarUrl = string.Format("{0}{1}", Configs.BaseWebUrl, serviceResult.Data.CreatorAvatarUrl);
                actionResult.CurrentPersonCount = serviceResult.Data.CurrentPersonCount;
                actionResult.Descritpion = serviceResult.Data.Descritpion;
                actionResult.IsFinished = serviceResult.Data.IsFinished;
                actionResult.Latitude = serviceResult.Data.Latitude;
                actionResult.Longitude = serviceResult.Data.Longitude;
                actionResult.MaxPersonCount = serviceResult.Data.MaxPersonCount;
                return new ActionResult<Results.GetActivityResult>(true, serviceResult.ErrorCode,
                    ErrorCode.ToString(serviceResult.ErrorCode), actionResult);
            }
            return new ActionResult<Results.GetActivityResult>(false, serviceResult.ErrorCode,
                    ErrorCode.ToString(serviceResult.ErrorCode), actionResult);
        }
    }
}
